﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MCUPic.Views
{
    [ToolboxItem(false)]
    public partial class PicItemView : UserControl
    {
        public event Action OnRemoved;
        private string _pathStr;
        public string PathStr
        {
            get { return _pathStr; }
            set
            {
                _pathStr = value;
                this.textBox1.Text = _pathStr;
            }
        }

        public PicItemView()
        {
            InitializeComponent();
            this.textBox1.MouseEnter += View_MouseEnter;
            this.MouseEnter += View_MouseEnter;
            this.btn_delete.MouseEnter += View_MouseEnter;
            this.textBox1.MouseLeave += View_MouseLeave;
            this.MouseLeave += View_MouseLeave;
            this.btn_delete.MouseLeave += View_MouseLeave;
            this.textBox1.MouseDown += (s, e) => 
            { 
                this.OnMouseDown(null); };
        }

        private void View_MouseEnter(object sender, EventArgs e)
        {
            this.BackColor = Color.FromArgb(215, 215, 215);
            this.textBox1.BackColor = this.BackColor;
        }

        private void View_MouseLeave (object sender,EventArgs e)
        {
            this.BackColor = Color.White;
            this.textBox1.BackColor = this.BackColor;
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.btn_delete.Location = new Point(this.Width - btn_delete.Width - 3, (this.Height - btn_delete.Height) / 2);
            this.textBox1.Location = new Point(2, (this.Height - this.textBox1.Height) / 2 + 2);
        }

        private void btn_delete_Click(object sender, EventArgs e)
        {
            Parent.Controls.Remove(this);
            OnRemoved?.Invoke();
            Dispose(true);
        }
    }
}
